package service

import "com.cyt.yunpay/app/service/pay/allinpay/core"

type MerchantService struct {
	base    *core.Pay
	service string
}

func NewMerchantService(base *core.Pay) *MerchantService {
	return &MerchantService{
		base:    base,
		service: "MerchantService",
	}
}

type GetCheckAccountFileReq struct {
	Date     string `json:"date"`
	FileType int    `json:"fileType"` //1明细 2汇总
}

type GetCheckAccountFileRsp struct {
	Url string `json:"url"`
}

// 商户集合对账文件下载
func (s *MerchantService) GetCheckAccountFile(req GetCheckAccountFileReq) (*GetCheckAccountFileRsp, error) {
	var res = &GetCheckAccountFileRsp{}
	err := s.base.CommonRequest(s.service, "getCheckAccountFile", req, res)
	return res, err
}

type QueryReserveFundBalanceRsp struct {
	AccountNo   string `json:"account_no"`
	AccountName string `json:"account_name"`
	Balance     int    `json:"balance"`
	DefClr      int    `json:"def_clr"`
}

// 平台余额查询
func (s *MerchantService) QueryReserveFundBalance() (*QueryReserveFundBalanceRsp, error) {
	var res = &QueryReserveFundBalanceRsp{}
	err := s.base.CommonRequest(s.service, "queryReserveFundBalance", nil, res)
	return res, err
}

type NotifySubAcctReserveFundInReq struct {
	BizUserId       string `json:"bizUserId"`
	AcctOrgType     int    `json:"acctOrgType"`
	SubAcctNo       string `json:"subAcctNo"`
	SubAcctName     string `json:"subAcctName"`
	AccountSetNo    string `json:"accountSetNo"`
	Trxid           string `json:"trxid"`
	OrderNo         string `json:"orderNo"`
	Status          string `json:"status"`
	ExAccountNo     string `json:"exAccountNo"`
	ExAccountName   string `json:"exAccountName"`
	ExUnionBank     string `json:"exUnionBank"`
	ExUnionBankName string `json:"exUnionBankName"`
	Amount          int    `json:"amount"`
	FundInTime      string `json:"fundInTime"`
	Summary         string `json:"summary"`
}

type NotifySubAcctReserveFundInRsp struct {
	Sysid       string `json:"sysid"`
	BizOrderNo  string `json:"bizOrderNo"`
	MerchantRet string `json:"merchantRet"`
}

// 会员子账号汇款入金上账通知
func (s *MerchantService) NotifySubAcctReserveFundIn(req NotifySubAcctReserveFundInReq) (*NotifySubAcctReserveFundInRsp, error) {
	var res = &NotifySubAcctReserveFundInRsp{}
	err := s.base.CommonRequest(s.service, "NotifySubAcctReserveFundIn", nil, res)
	return res, err
}

type QueryMerchantBalanceReq struct {
	AccountSetNo string `json:"accountSetNo"`
}

type QueryMerchantBalanceRsp struct {
	AllAmount    int `json:"allAmount"`
	FreezeAmount int `json:"freezeAmount"`
}

// 平台账户集余额查询
func (s *MerchantService) QueryMerchantBalance(req QueryMerchantBalanceReq) (*QueryMerchantBalanceRsp, error) {
	var res = &QueryMerchantBalanceRsp{}
	err := s.base.CommonRequest(s.service, "queryMerchantBalance", req, res)
	return res, err
}

type QueryBankBalanceReq struct {
	AcctOrgType int    `json:"acctOrgType"`
	AcctNo      string `json:"acctNo"`
	AcctName    string `json:"acctName"`
}

type QueryBankBalanceRsp struct {
	AcctOrgType int    `json:"acctOrgType"`
	AcctNo      string `json:"acctNo"`
	AcctName    string `json:"acctName"`
	Balance     int    `json:"balance"`
}

// 平台银行存管账户余额查询
func (s *MerchantService) QueryBankBalance(req QueryBankBalanceReq) (*QueryBankBalanceRsp, error) {
	var res = &QueryBankBalanceRsp{}
	err := s.base.CommonRequest(s.service, "queryBankBalance", req, res)
	return res, err
}

type QueryBankInExpDetailReq struct {
	AcctOrgType   int    `json:"acctOrgType"`
	StartDate     string `json:"startDate"`
	EndDate       string `json:"endDate"`
	IsFirstFlag   int    `json:"isFirstFlag"`
	StartPosition int    `json:"startPosition"`
	QueryNum      int    `json:"queryNum"`
}

type QueryInExpDetail struct {
	TradeNo        string `json:"tradeNo"`
	TxnTime        string `json:"txnTime"`
	OriAcctBalance int    `json:"oriAcctBalance"`
	Balance        int    `json:"balance"`
	PreAcctBalance int    `json:"preAcctBalance"`
	Summary        string `json:"summary"`
	Remark         string `json:"remark"`
	TradeFlag      string `json:"tradeFlag"`
}

type QueryBankInExpDetailRsp struct {
	AcctOrgType int                `json:"acctOrgType"`
	AcctName    string             `json:"acctName"`
	TotalNum    int                `json:"totalNum"`
	InExpDetail []QueryInExpDetail `json:"inExpDetail"`
}

//平台银行存管账户余额查询
func (s *MerchantService) QueryBankInExpDetail(req QueryBankInExpDetailReq) (*QueryBankInExpDetailRsp, error) {
	var res = &QueryBankInExpDetailRsp{}
	err := s.base.CommonRequest(s.service, "queryBankInExpDetail", req, res)
	return res, err
}

type EleReceiptDownloadReq struct {
	BizOrderNo string `json:"bizOrderNo"`
}

type EleReceiptDownloadRsp struct {
	Url string `json:"url"`
}

//电子回单下载
func (s *MerchantService) EleReceiptDownload(req EleReceiptDownloadReq) (*EleReceiptDownloadRsp, error) {
	var res = &EleReceiptDownloadRsp{}
	err := s.base.CommonRequest(s.service, "eleReceiptDownload", req, res)
	return res, err
}
